package doudizhu2;

import java.util.*;

public class PokerGame {
    //创建双列集合
    static HashMap<Integer, String> hm = new HashMap<>();
    static ArrayList<Integer> list = new ArrayList<>();

    //准配牌
    static {
        String[] color = {"♠", "♥", "♣", "♦"};
        String[] number = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        //序号
        int severalNember = 1;
        //利用for循环进行组合
        for (String n : number) {
            for (String c : color) {
                hm.put(severalNember, c + n);
                list.add(severalNember);
                severalNember++;
            }
        }

        //添加大小王
        hm.put(severalNember, "大王");
        list.add(severalNember);
        severalNember++;
        hm.put(severalNember, "小王");
        list.add(severalNember);
        //System.out.println(hm);
    }

    public PokerGame() {
        //洗牌
        Collections.shuffle(list);
        //发牌
        //创建三个集合
        //依次表示三个玩游戏的人
        TreeSet<Integer> dipai = new TreeSet<>();
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();
        for (int i = 0; i < list.size(); i++) {
            int severalNumber = list.get(i);

            if (i <= 2) {
                dipai.add(severalNumber);
                continue;
            }

            //分配给玩游戏的三个人
            if (i % 3 == 0) {
                player1.add(severalNumber);
            } else if (i % 3 == 1) {
                player2.add(severalNumber);
            } else {
                player3.add(severalNumber);
            }
        }

        lookPuker("底牌",dipai);
        lookPuker("李四",player1);
        lookPuker("王五",player2);
        lookPuker("赵六",player3);

    }

    //看牌
    public void lookPuker(String name, TreeSet<Integer> ts) {
        System.out.print(name + " :");
        for (int severalNumber : ts) {
            String puker = hm.get(severalNumber);
            System.out.print(puker + " ");
        }
        System.out.println();
    }
}
